/*************************************************************************
 *  Copyright © 2023-2030 FXB CO.,LTD. All rights reserved.
 *------------------------------------------------------------------------
 *  公司：DefaultCompany
 *  项目：CustomBuildProcess
 *  文件：BuildConfigItem.cs
 *  作者：Administrator
 *  日期：2025/6/10 20:16:13
 *  功能：Nothing
*************************************************************************/

using System;
using System.Collections;
using System.Collections.Generic;
using System.Linq;
using UnityEngine;

namespace CustomBuildProcess.Editor
{
    [System.Serializable]
    public class LogItemKeyValuePair : IEquatable<LogItemKeyValuePair>
    {
        public string key;
        public string value;
        public LogItemKeyValuePair(string key, string value)
        {
            this.key = key;
            this.value = value;
        }

        // 实现 IEquatable<T> 接口（可选，但推荐）
        public bool Equals(LogItemKeyValuePair other)
        {
            if (other is null) return false;
            if (ReferenceEquals(this, other)) return true;
            return key == other.key || value == other.value;   //这块特殊处理，主要用于列表的Contains方法，判断key或value相同既认为相等
        }

        // 重写 Object.Equals
        public override bool Equals(object obj) => Equals(obj as LogItemKeyValuePair);

        // 重写 GetHashCode（必须与 Equals 逻辑一致）
        public override int GetHashCode()
        {
            unchecked // 允许整数溢出
            {
                int hash = 17;
                hash = hash * 23 + (key?.GetHashCode() ?? 0);
                hash = hash * 23 + (value?.GetHashCode() ?? 0);
                return hash;
            }
        }

        // ✅ 运算符重载：==
        public static bool operator ==(LogItemKeyValuePair left, LogItemKeyValuePair right)
        {
            if (ReferenceEquals(left, right)) return true;  // 两者为同一对象或均为 null
            if (left is null || right is null) return false; // 一方为 null
            return left.Equals(right); // 调用 Equals 方法
        }

        // ✅ 运算符重载：!=
        public static bool operator !=(LogItemKeyValuePair left, LogItemKeyValuePair right) => !(left == right);

        public override string ToString()
        {
            return $"{key}-{value}";
        }
    }

    [System.Serializable]
    public class BuildConfigItem : ScriptableObject
    {
        [HideInInspector]
        public List<LogItemKeyValuePair> types = new List<LogItemKeyValuePair>()
        {
            new LogItemKeyValuePair("StandAlone","单机版"),
            new LogItemKeyValuePair("Licence","注册版"),
            new LogItemKeyValuePair("Web","网页版")
        };

        [HideInInspector]
        public List<LogItemKeyValuePair> languages = new List<LogItemKeyValuePair>()
        {
            new LogItemKeyValuePair("Chinese","中文"),
            new LogItemKeyValuePair("English","英文"),
            new LogItemKeyValuePair("Japanese","日语"),
            new LogItemKeyValuePair("Korean","韩语"),
            new LogItemKeyValuePair("French","法语"),
            new LogItemKeyValuePair("German","德语"),
            new LogItemKeyValuePair("Spanish","西班牙语"),
            new LogItemKeyValuePair("Russian","俄语"),
        };

        [HideInInspector]
        public List<LogItemKeyValuePair> models = new List<LogItemKeyValuePair>()
        {
            new LogItemKeyValuePair("None","None"),
            new LogItemKeyValuePair("QinEV","秦EV"),
            new LogItemKeyValuePair("QinPlus","秦PlusEV"),
            new LogItemKeyValuePair("QinDMi","秦PlusDMi"),
            new LogItemKeyValuePair("E5","比亚迪E5"),
            new LogItemKeyValuePair("Dolphin","比亚迪海豚"),
            new LogItemKeyValuePair("EV450","帝豪EV450"),
            new LogItemKeyValuePair("Magotan","迈腾"),
            new LogItemKeyValuePair("iD4","大众ID4"),
            new LogItemKeyValuePair("Motor","电机"),
            new LogItemKeyValuePair("Battery","电池"),
            new LogItemKeyValuePair("Charge","充电桩"),
        };

        [HideInInspector]
        public List<LogItemKeyValuePair> features = new List<LogItemKeyValuePair>()
        {
            new LogItemKeyValuePair("PLC","PLC"),
            new LogItemKeyValuePair("Protection","高压保护"),
            new LogItemKeyValuePair("ShareTravel","共享出行"),
            new LogItemKeyValuePair("Adjustment","装调"),
            new LogItemKeyValuePair("Mechanic","机械工程"),
            new LogItemKeyValuePair("AutoDrive","自动驾驶"),
            new LogItemKeyValuePair("DigitalTwin","数字孪生"),
            new LogItemKeyValuePair("Disassembly","虚拟拆装"),
            new LogItemKeyValuePair("Maintenance","维护保养"),
            new LogItemKeyValuePair("Diagnosis","故障诊断"),
            new LogItemKeyValuePair("Structure","结构展示"),
            new LogItemKeyValuePair("Resource","资源包"),
            new LogItemKeyValuePair("ICV","智能网联"),
            new LogItemKeyValuePair("Assembly","装配"),
            new LogItemKeyValuePair("Repair","检修"),
        };

        [HideInInspector]
        public List<LogItemKeyValuePair> platforms = new List<LogItemKeyValuePair>()
        {
            new LogItemKeyValuePair("PC","电脑端"),
            new LogItemKeyValuePair("VR","沉浸VR"),
            new LogItemKeyValuePair("Voxel","桌面VR"),
            new LogItemKeyValuePair("Voxel3D","3D全息"),
            new LogItemKeyValuePair("Android","手机端"),
            new LogItemKeyValuePair("WebGL","网页端"),
        };

        public int GetTypesIndex(string type)
        {
            return types.FindIndex(item => item.key == type);
        }

        public List<string> GetTypesValues()
        {
            return types.Select(item =>$"{item.key} ({item.value})" ).ToList();
        }

        public LogItemKeyValuePair GetType(string type)
        {
            return types.FirstOrDefault(item => item.key == type);
        }

        public int GetLanguagesIndex(string language)
        {
            return languages.FindIndex(item => item.key == language);
        }

        public List<string> GetLanguagesValues()
        {
            return languages.Select(item => $"{item.key} ({item.value})").ToList();
        }

        public LogItemKeyValuePair GetLanguage(string language)
        {
            return languages.FirstOrDefault(item => item.key == language);
        }

        public int GetModelsIndex(string model)
        {
            return models.FindIndex(item => item.key == model);
        }

        public List<string> GetModelsValues()
        {
            return models.Select(item => $"{item.key} ({item.value})").ToList();
        }

        public LogItemKeyValuePair GetModel(string model)
        {
            return models.FirstOrDefault(item => item.key == model);
        }

        public int GetFeaturesIndex(string feature)
        {
            return features.FindIndex(item => item.key == feature);
        }

        public List<string> GetFeaturesValues()
        {
            return features.Select(item => $"{item.key} ({item.value})").ToList();
        }

        public LogItemKeyValuePair GetFeature(string feature)
        {
            return features.FirstOrDefault(item => item.key == feature);
        }


        public int GetPlatformsIndex(string platform)
        {
            return platforms.FindIndex(item => item.key == platform);
        }

        public List<string> GetPlatformsValues()
        {
            return platforms.Select(item => $"{item.key} ({item.value})").ToList();
        }

        public LogItemKeyValuePair GetPlatform(string platform)
        {
            return platforms.FirstOrDefault(item => item.key == platform);
        }
    }
}


